﻿#region Imports
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using CommonUtilities.Attributes;
using CommonUtilities.Enums;
using CommonUtilities.Extensions;
using CommonUtilities.Util;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endregion

namespace CommonUtilities.UnitTest
{
    [TestClass]
    public class Utilities_Test
    {
        #region Extension methods
        [TestMethod]
        public void GetSuggestedName_Test()
        {
            string pattern = "";
            string fileNames = @"C:\[songs.pk] 01 - Dhan Tan Na (male).mp3
                                 C:\[songs.pk] 02 - Dhan Tan Na (female).mp3";
            List<string> lstFileNames = fileNames.ConvertStringToLines()
                .Select(fl => Path.GetFileNameWithoutExtension(fl.Trim())).ToList();

            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Left);
            MessageBox.Show(pattern, "Left :: Auto length");
            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Left, 12);
            MessageBox.Show(pattern, "Left :: 12 -> 12");
            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Left, 14);
            MessageBox.Show(pattern, "Left :: 12 -> 14");

            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Right);
            MessageBox.Show(pattern, "Right :: Auto length");
            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Right, 5);
            MessageBox.Show(pattern, "Right :: 5 -> 5");
            pattern = Utilities.GetSuggestedPattern(lstFileNames, eTrimDirection.Right, 8);
            MessageBox.Show(pattern, "Right :: 5 -> 8");
        }

        [TestMethod]
        public void HasDefaultCtor_Test()
        {
            // EXPECTED
            bool expectedBrowsable = Utilities.HasDefaultCtor<BrowsableAttribute>();   //.GetConstructors.GetConstructors()._Where(ctor => ctor.GetParameters().HasCount(0))._Any();
            bool expectedDisplayName = Utilities.HasDefaultCtor<DisplayNameAttribute>();   //.GetConstructors()._Where(ctor => ctor.GetParameters().HasCount(0))._Any();
            bool expectedUnique = Utilities.HasDefaultCtor<UniqueAttribute>();   //.GetConstructors()._Where(ctor => ctor.GetParameters().HasCount(0))._Any();

            // RESULT
            Assert.AreEqual(expectedBrowsable, false);
            Assert.AreEqual(expectedDisplayName, true);
            Assert.AreEqual(expectedUnique, true);
        }
        #endregion

        [TestMethod]
        public void ConvertNumToWords_Test_299()
        {
            string expected = "Two hundred and twenty nine";
            string actual = NumberHelper.ConvertNumToWords(229);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void ConvertNumToWords_Test_1005()
        {
            string expected = "One thousand and five";
            string actual = NumberHelper.ConvertNumToWords(1005);

            Assert.AreEqual(expected, actual);
        }
    }
}
